package de.hhkk.view.stammdaten;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.nebula.widgets.calendarcombo.CalendarCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;

import de.hhkk.controller.NavigationController;

public class UIMaterialSuchen extends Composite
{
    private Text  text;
    private Table table;
    private Text  text_2;
    private Text  text_4;
    private Text  text_5;
    private Text  text_1;
    private Text  text_3;
    private Text  text_6;
    private Text  text_7;
    private Text  text_9;

    /**
     * Create the composite.
     * @param parent
     * @param style
     */
    public UIMaterialSuchen(Composite parent, int style, String title)
    {
        super(parent, style);
        setLayout(new FillLayout(SWT.HORIZONTAL));

        TabFolder tabFolder = new TabFolder(this, SWT.NONE);
        tabFolder.setBounds(0, 0, 122, 43);

        TabItem tbtmNewItem = new TabItem(tabFolder, SWT.NONE);
        tbtmNewItem.setText(title);

        Composite composite = new Composite(tabFolder, SWT.NONE);
        tbtmNewItem.setControl(composite);
        composite.setLayout(new GridLayout(1, false));

        Group group = new Group(composite, SWT.NONE);
        GridData gd_group = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
        gd_group.heightHint = 172;
        gd_group.widthHint = 660;
        group.setLayoutData(gd_group);
        group.setText("Suchkriterien");
        group.setBounds(0, 0, 650, 227);
        group.setLayout(new GridLayout(8, false));

        Label lblKundenr = new Label(group, SWT.NONE);
        lblKundenr.setAlignment(SWT.RIGHT);
        lblKundenr.setText("Artikel-Nr.");

        text = new Text(group, SWT.BORDER);
        GridData gd_text = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
        gd_text.widthHint = 140;
        text.setLayoutData(gd_text);
        // Nur Zahlen erlauben
        text.addListener(SWT.Verify, new Listener()
        {
            @Override
            public void handleEvent(Event e)
            {
                String string = e.text;
                char[] chars = new char[string.length()];
                string.getChars(0, chars.length, chars, 0);
                for (int i = 0; i < chars.length; i++)
                {
                    if (!('0' <= chars[i] && chars[i] <= '9'))
                    {
                        e.doit = false;
                        return;
                    }
                }
            }
        });

        Label lblStrae = new Label(group, SWT.NONE);
        lblStrae.setText("Artikelgruppe");

        text_2 = new Text(group, SWT.BORDER);
        text_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label lblTel = new Label(group, SWT.NONE);
        lblTel.setText("Reparaturstatus");

        text_7 = new Text(group, SWT.BORDER);
        text_7.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label label_1 = new Label(group, SWT.SEPARATOR);
        label_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 4));
        new Label(group, SWT.NONE);

        Label lblKurzbezeichnung = new Label(group, SWT.NONE);
        lblKurzbezeichnung.setText("Kurzbezeichnung");

        text_1 = new Text(group, SWT.BORDER);
        text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label lblSchden = new Label(group, SWT.NONE);
        lblSchden.setText("Sch\u00E4den");

        text_6 = new Text(group, SWT.BORDER);
        text_6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label lblLand = new Label(group, SWT.NONE);
        lblLand.setText("Kaufdatum");

        CalendarCombo calendarCombo = new CalendarCombo(group, SWT.NONE);
        new Label(group, SWT.NONE);

        Label lblBezeichnung = new Label(group, SWT.NONE);
        lblBezeichnung.setText("Bezeichnung");

        text_3 = new Text(group, SWT.BORDER);
        text_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label lblNote = new Label(group, SWT.NONE);
        lblNote.setText("Note");

        text_4 = new Text(group, SWT.BORDER);
        text_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        // Nur Zahlen erlauben
        text_4.addListener(SWT.Verify, new Listener()
        {
            @Override
            public void handleEvent(Event e)
            {
                String string = e.text;
                char[] chars = new char[string.length()];
                string.getChars(0, chars.length, chars, 0);
                for (int i = 0; i < chars.length; i++)
                {
                    if (!('0' <= chars[i] && chars[i] <= '9'))
                    {
                        e.doit = false;
                        return;
                    }
                }
            }
        });
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);

        Label lblReparaturstatus = new Label(group, SWT.NONE);
        lblReparaturstatus.setText("Artikeltyp");

        text_9 = new Text(group, SWT.BORDER);
        text_9.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Label lblEmpfehlung = new Label(group, SWT.NONE);
        lblEmpfehlung.setText("Empfehlung");

        text_5 = new Text(group, SWT.BORDER);
        text_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);

        Button button = new Button(group, SWT.NONE);
        button.setText("Suchen");
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);

        Label label_8 = new Label(group, SWT.NONE);
        label_8.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

        Label label_9 = new Label(group, SWT.NONE);
        GridData gd_label_9 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
        gd_label_9.widthHint = 69;
        label_9.setLayoutData(gd_label_9);
        Label label_3 = new Label(group, SWT.NONE);
        label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        Label label_6 = new Label(group, SWT.NONE);
        label_6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE);

        Group group_1 = new Group(composite, SWT.NONE);
        group_1.setText("Trefferliste");
        group_1.setBounds(0, 0, 650, 252);
        group_1.setLayout(new GridLayout(1, false));

        TableViewer tableViewer = new TableViewer(group_1, SWT.BORDER | SWT.FULL_SELECTION);
        table = tableViewer.getTable();
        table.setLinesVisible(true);
        table.setHeaderVisible(true);
        GridData gd_table = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1);
        gd_table.widthHint = 657;
        gd_table.heightHint = 203;
        table.setLayoutData(gd_table);

        TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
        TableColumn tblclmnKundennr = tableViewerColumn.getColumn();
        tblclmnKundennr.setWidth(100);
        tblclmnKundennr.setText("Artikel-Nr.");
        tblclmnKundennr.setResizable(true);
        tblclmnKundennr.setMoveable(true);

        Composite composite_1 = new Composite(composite, SWT.NONE);
        GridData gd_composite_1 = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
        gd_composite_1.widthHint = 164;
        composite_1.setLayoutData(gd_composite_1);
        composite_1.setBounds(0, 0, 157, 35);
        composite_1.setLayout(new GridLayout(2, false));

        Button btnNeuanlegen = new Button(composite_1, SWT.NONE);
        btnNeuanlegen.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                material();
            }
        });
        btnNeuanlegen.setText("Neu anlegen");

        Button btnSchliessen = new Button(composite_1, SWT.NONE);
        btnSchliessen.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                NavigationController.getInstance().clear();
                dispose();
            }
        });
        btnSchliessen.setText("Schlie\u00DFen");

    }

    @Override
    protected void checkSubclass()
    {
        // Disable the check that prevents subclassing of SWT components
    }

    public void material()
    {

//        StackLayout layout = (StackLayout) getParent().getLayout();
//        UIMaterialNeu material = new UIMaterialNeu(getParent(), SWT.NONE, "Artikel anlegen");
//        NavigationController navCon = NavigationController.getInstance();
//        navCon.push(material);
//        layout.topControl = material;
//        getParent().layout();

    }
}
